<template>
  <div class="my-container">
    <div v-if="!user" class="header not-login">
      <div class="login-btn" @click="$router.push('/login')">
        <img class="mobile-img" src="~@/assets/mobile.png" />
        <span class="text">登录 / 注册</span>
      </div>
    </div>
    <div v-else class="header isLogin">
      <!-- top -->
      <div class="user-info">
        <!-- left -->
        <div class="user-attract">
          <van-image
            class="mobile-img"
            round
            fit="cover"
            :src="userInfo.photo"
          />
        </div>
        <span class="user-name">{{ userInfo.name }}</span>
        <!-- rigth -->
        <div class="user-edit">
          <van-button size="mini" round to="/user/user_profile">
            编辑资料
          </van-button>
        </div>
      </div>
      <!-- bottom -->
      <div class="data-status">
        <div class="data">
          <div class="data-item">
            <span>{{ userInfo.art_count }}</span>
            <span>头条</span>
          </div>
          <div class="data-item">
            <span>{{ userInfo.like_count }}</span>
            <span>关注</span>
          </div>
          <div class="data-item">
            <span>{{ userInfo.fans_count }}</span>
            <span>粉丝</span>
          </div>
          <div class="data-item">
            <span>{{ userInfo.follow_count }}</span>
            <span>获赞</span>
          </div>
        </div>
      </div>
    </div>
    <!-- 宫格 -->
    <van-grid class="nav-grid" :column-num="2" clickable>
      <van-grid-item text="收藏">
        <i slot="icon" class="headLine headLine-shoucang"></i>
        <span class="text" slot="text">收藏</span>
      </van-grid-item>
      <van-grid-item text="文字">
        <i slot="icon" class="headLine headLine-lishi"></i>
        <span class="text" slot="text">历史</span>
      </van-grid-item>
    </van-grid>
    <!-- 单元格 导航栏 -->
    <van-cell title="消息通知" is-link />
    <van-cell title="小智同学" is-link />
    <van-cell
      v-if="user"
      class="logout-cell"
      clickable
      title="退出登录"
      center
      @click="outlogin()"
    />
  </div>
</template>

<script>
import { userBaseInfoApi } from '@/api/index.js'
import { mapState } from 'vuex'
export default {
  name: 'MyIndex',
  components: {},
  props: {},
  data() {
    return {
      userInfo: []
    }
  },
  computed: {
    ...mapState(['user'])
  },
  watch: {},
  created() {
    if (this.user) {
      this.loadUserInfo()
    }
  },
  mounted() {},
  methods: {
    outlogin() {
      this.$dialog
        .confirm({
          title: '退出登录',
          message: '确认退出嘛？'
        })
        .then(() => {
          // this.$store.state.user = null
          this.$store.commit('saveUserInfo', null)
        })
        .catch(() => {
          // on cancel
        })
    },
    async loadUserInfo() {
      try {
        const { data } = await userBaseInfoApi()
        console.log(data.data)
        this.userInfo = data.data
      } catch (err) {
        console.log()
        console.log(err)
      }
    }
  }
}
</script>

<style scoped lang="less">
.my-container {
  .header {
    width: 750px;
    height: 381px;
    background: url('~@/assets/banner.png');
  }
  .not-login {
    display: flex;
    justify-content: center;
    .login-btn {
      display: flex;
      flex-direction: column;
      align-items: center;
      margin-top: 12.5%;
      // justify-content: center;
      width: 132px;
      height: 132px;
      .mobile-img {
        width: 132px;
        height: 132px;
      }
      .text {
        display: block;
        width: 120px;
        height: 14px;
        font-size: 14px;
        font-weight: normal;
        color: #ffffff;
        margin-top: 15px;
      }
    }
  }
  .isLogin {
    /deep/ .user-info {
      height: 230px;
      padding: 76px 32px 23px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      box-sizing: border-box;
      .user-attract {
        // height: 100%;
        display: flex;
        align-items: center;
        .mobile-img {
          width: 132px;
          height: 132px;
          border: 2px solid #fff;
        }
        /deep/ .user-name {
          font-size: 29px;
          margin-right: 210px;
        }
      }
      .user-edit {
        width: 150px;
      }
    }
    .data-status {
      height: 150px;
      .data {
        display: flex;
        justify-content: space-around;
        .data-item {
          height: 130px;
          display: flex;
          align-items: center;
          justify-content: center;
          flex-direction: column;
          color: #fff;
          span:nth-child(1) {
            font-size: 36px;
            margin-bottom: 15px;
          }
          span:nth-child(2) {
            font-size: 23px;
          }
        }
      }
    }
  }
  // 历史
  .nav-grid {
    background: #fff;
    .headLine {
      font-size: 45px;
    }
    .headLine-shoucang {
      color: #eb5253;
    }
    .headLine-lishi {
      color: #ff9d1d;
    }
    .text {
      color: #000;
      margin-top: 8px;
      font-size: 28px;
    }
  }
  .logout-cell {
    height: 100px;
    text-align: center;
    color: #eb5253;
    margin: 10px 0;
    font-size: 30px;
  }
}
</style>
